<%@ page import="cn.cjxy.domain.User" %>
<%@ page import="java.util.Arrays" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.HashMap" %><%--
  Created by IntelliJ IDEA.
  User: 12460
  Date: 2024/11/30
  Time: 14:48
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title> EL表达式获取不同类型的数据</title>
</head>
<body>
    <h2>取对象</h2>
    <%
        //将用户对象存入作用域
        User user = new User(1, "张三");
        pageContext.setAttribute("user", user);
    %>
    <h2>得到javaBean的属性值</h2>
   <%-- 本质上就是调用get方法--%>
    对象本身：${user} <br>
    id:${user.id}    <br>
    用户名:${user.username}

    <h2>取出list集合中的元素</h2>
    <%
        List<String> list = Arrays.asList("重庆", "陕西", "湖南", "北京");
        request.setAttribute("city",list);
    %>
    <%-- 取的是键--%>
    ${city} <br>
    ${city[0]} &nbsp; ${city[1]} &nbsp;   ${city[2]} &nbsp; ${city[3]}
    <h2>取出数组中的元素</h2>
    <%
       int[] nums={1,2,3,4,5,6,7};
       //存入作用域
        session.setAttribute("nums",nums);
    %>
    ${nums} <br>
    ${nums[0]} &nbsp; ${nums[1]} &nbsp;   ${nums[2]} &nbsp; ${nums[3]}

    <h2>取出map中的元素</h2>
    <%
        HashMap<String, String> maps = new HashMap<>();
        //存入值  键-值的形式
        maps.put("city1","重庆");
        maps.put("city2","陕西");
        maps.put("city3","湖南");
        maps.put("city4","北京");
        //放入请求域
        request.setAttribute("maps",maps);
    %>
    ${maps} <br>
    <%-- 如果变量为空，返回true--%>
    ${empty maps}
    <%-- map对象.键名--%>
    ${maps.city1} <br>
    ${maps.city2}  <br>
    ${maps.city3}   <br>
    ${maps.city4}   <br>
</body>
</html>
